-- || Created by Revelse

Player = inherit(Object)
registerElementClass("player",Player)

function Player:constructor()
	self.m_Data = {}
end

function Player:leaveLobby()
	
	if self:getGamemode() then
		self:getGamemode():getRooms()[self:getRoomID()]:removePlayer(self)	
	end
end

function Player:onVote()
	
end

function Player:setData(key,value,syncToClient)
	
	self.m_Data[value] = key
	
	if syncToClient then
		setElementData(self,key,value)
	end
end

function Player:getGamemode()   return self.currentGamemode end
function Player:getRoomID()     return self.currentRoomID   end

function Player:triggerEvent(event,...)
	triggerClientEvent(self,event,self,...)
end

function Player:sendMessage(text,r,g,b,...)
	outputChatBox((text):format(...),self,r,g,b,true)
end

function Player:getData(key)
	return self.m_Data[key]
end

function Player:getAllData()
	return self.m_Data
end

function Player:join()
	--[[
	spawnPlayer(self,0,0,5)
	setCameraTarget(self,self)]]
	fadeCamera(self,true)
	LoginRegister:getSingleton():sendPlayerTo(self)
end

function Player:spawnPlayer(...)
	setCameraTarget(self,self)
	spawnPlayer(self,...)
end

function Player:kickPlayer()
	kickPlayer(self)
end

function Player:save()
	return
	mysql:exec("UPDATE playerData SET data = ? WHERE Name = ?", toJSON(self:getAllData()), getPlayerName(self))
end

function Player:destructor()
	if self:getGamemode() then
		self:getGamemode():getRooms()[self:getRoomID()]:removePlayer(self)
	end
	self:save()
end